/*
 * MainFrame.h
 *
 *  Created on: Aug 25, 2011
 *      Author: erudhes
 */

#ifndef MAINFRAME_H_
#define MAINFRAME_H_
#include <wx/wx.h>

class MainPanel;
class MessagingFrame;

class MainFrame : public wxFrame
{
	public:
		enum
		{
			// Window or dialog IDs
			MAIN_FRAME_WIN_ID = 5500,
			MESSAGING_FRAME_WIN_ID,
			MAIN_FRAME_MENU_NEW_HOST_DIALOG_ID,
			MAIN_FRAME_MENU_NEW_JOIN_DIALOG_ID,
			MAIN_FRAME_MENU_CONFIGURE_DIALOG_ID,
			// Menu IDs
			MAIN_FRAME_MENU_NEW_HOST_START_HOSTING_ID = 5600,
			MAIN_FRAME_MENU_NEW_HOST_CHANGE_LEVEL_ID,
			MAIN_FRAME_MENU_NEW_HOST_KICK_OFF_CLIENT_ID,
			MAIN_FRAME_MENU_NEW_JOIN_ID,
			MAIN_FRAME_MENU_RESTART_ID,
			MAIN_FRAME_MENU_CLOSE_ID,
			MAIN_FRAME_MENU_EXIT_ID,
			MAIN_FRAME_MENU_CONFIGURE_ID,
			MAIN_FRAME_MENU_MESSAGING_ID,
			MAIN_FRAME_MENU_ENABLE_MESSAGING_ID,
			MESSAGING_FRAME_MENU_EXIT_ID,
			// Any other IDs
			MAIN_FRAME_HOST_CANCEL_BUTTON_ID = 5700,
			MAIN_FRAME_JOIN_IP_PANEL_ID,
			MAIN_FRAME_JOIN_IP_TEXT_ID,
			MAIN_FRAME_JOIN_PORT_TEXT_ID,
			MAIN_FRAME_JOIN_OK_BUTTON_ID,
			MAIN_FRAME_JOIN_CANCEL_BUTTON_ID,
			MAIN_FRAME_CONFIGURE_OK_BUTTON_ID,
			MAIN_FRAME_CONFIGURE_CANCEL_BUTTON_ID,
			MAIN_FRAME_CONFIGURE_LOGO_TEXT_ID,
			MAIN_FRAME_CONFIGURE_DOT_SIZE_TEXT_ID,
			MAIN_FRAME_CONFIGURE_PORT_NUMBER_TEXT_ID,
			MAIN_FRAME_CONFIGURE_FREQUENCY_TEXT_ID,
			MAIN_FRAME_CONFIGURE_FREE_SERVERS_CHECK_BOX_ID,
			MAIN_FRAME_CONFIGURE_DOWNLOAD_UNKNOWN_LEVELS_CHECK_BOX_ID,
			MAIN_FRAME_CONFIGURE_UPLOAD_LEVELS_CHECK_BOX_ID,
			MAIN_FRAME_CONFIGURE_REGISTER_SERVER_CHECK_BOX_ID,
			MAIN_FRAME_CONFIGURE_PROXY_CHECK_BOX_ID,
			MAIN_FRAME_CONFIGURE_PROXY_HOST_TEXT_ID,
			MAIN_FRAME_CONFIGURE_PROXY_PORT_TEXT_ID,
			MAIN_FRAME_CONFIGURE_LEVEL_CHOICE_ID,
			MAIN_FRAME_CONFIGURE_VEHICLE_A_X_TEXT_ID,
			MAIN_FRAME_CONFIGURE_VEHICLE_A_Y_TEXT_ID,
			MAIN_FRAME_CONFIGURE_VEHICLE_B_X_TEXT_ID,
			MAIN_FRAME_CONFIGURE_VEHICLE_B_Y_TEXT_ID,
			MESSAGING_FRAME_MESSAGING_TEXT_CTRL_ID,
			MESSAGING_FRAME_MESSAGE_SENDING_TEXT_CTRL_ID,
			MESSAGING_FRAME_MESSAGE_SENDING_BUTTON_ID,
			MESSAGING_FRAME_STATUS_BAR_ID,
		};
		enum DialogMessageType
		{
			INVALID,
			SERVER_ERROR,
			CLIENT_ERROR,
			USER_ERROR,
			GAME_START,
			GAME_FINISH,
		};
		struct JoiningData
		{
			wxString mData;
			int mPort;
		};
		MainFrame(const wxString& title, long style = wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN);
		virtual ~MainFrame();
		void onMenuNewHostClicked(wxCommandEvent& menuEvent);
		void onMenuNewHostKickOffClicked(wxCommandEvent& menuEvent);
		void onMenuNewJoinClicked(wxCommandEvent& menuEvent);
		void onMenuRestartClicked(wxCommandEvent& menuEvent);
		void onMenuCloseClicked(wxCommandEvent& menuEvent);
		void onMenuExitClicked(wxCommandEvent& menuEvent);
		void onMenuConfigureClicked(wxCommandEvent& menuEvent);
		void onMenuMessagingClicked(wxCommandEvent& menuEvent);
		void showMessageDialog(const wxString& message, DialogMessageType messageType);
		void onClicked(wxCommandEvent& commandEvent);
		void onLevelSelected(wxCommandEvent& commandEvent);
		void onProxyChecked(wxCommandEvent& commandEvent);
		void onMainPanelClientSizeChange(const wxSize& newClientSize);
		void setHostEnabled(bool enabled);
		void setJoinEnabled(bool enabled);
		void setRestartEnabled(bool enabled);
		void setMessagingEnabled(bool enabled);
		bool isMessagingEnabled();
		void setConfigureEnabled(bool enabled);
		void setStartHostingEnabled(bool enabled);
		void setChangeLevelEnabled(bool enabled);
		void setKickOffClientEnabled(bool enabled);
		wxStatusBar* getStatusBar();
		MainPanel* getMainPanel();
		MessagingFrame* getMessagingFrame();
		bool isMessagingFrameOpened();
		void createMessagingFrame();
		void onMessageFrameClosed();

	private:
		MainPanel* mMainPanel;
		wxStatusBar* mStatusBar;
		MessagingFrame* mMessagingFrame;
		bool mIsServerStarting;

		DECLARE_EVENT_TABLE()
};

inline void MainFrame::setHostEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(0)->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[0]->Enable(enabled);
}

inline void MainFrame::setJoinEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(0)->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[1]->Enable(enabled);
}

inline void MainFrame::setRestartEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(0)->GetMenuItems()[1]->Enable(enabled);
}

inline void MainFrame::setMessagingEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(2)->GetMenuItems()[0]->Enable(enabled);
}

inline bool MainFrame::isMessagingEnabled()
{
	return this->GetMenuBar()->GetMenu(2)->GetMenuItems()[1]->IsChecked();
}

inline void MainFrame::setConfigureEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(1)->GetMenuItems()[0]->Enable(enabled);
}

inline void MainFrame::setStartHostingEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(0)->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[0]->Enable(enabled);
}

inline void MainFrame::setChangeLevelEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(0)->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[1]->Enable(enabled);
}

inline void MainFrame::setKickOffClientEnabled(bool enabled)
{
	this->GetMenuBar()->GetMenu(0)->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[0]->GetSubMenu()->GetMenuItems()[2]->Enable(enabled);
}

inline wxStatusBar* MainFrame::getStatusBar()
{
	return mStatusBar;
}

inline MainPanel* MainFrame::getMainPanel()
{
	return mMainPanel;
}

inline MessagingFrame* MainFrame::getMessagingFrame()
{
	return mMessagingFrame;
}

inline bool MainFrame::isMessagingFrameOpened()
{
	return mMessagingFrame != NULL;
}

inline void MainFrame::onMessageFrameClosed()
{
	mMessagingFrame = NULL;
}

#endif /* MAINFRAME_H_ */
